import sys

from api.api_register_login import ApiRegisterLogin

sys.path.append("D:\\Day\\p2p")
import pytest
import requests
from tools import read_html, common_assert, GetLog, read_json


logger = GetLog.get_logger()
class TestInvest:
    # 1、初始化
    def setup_method(self):
        self.session = requests.Session()
        sys.path.append("D:\\Day\\p2p\\api\\api_invest")
        from api.api_invest import ApiInvest
        self.invest = ApiInvest(self.session)
        ApiRegisterLogin(self.session).api_login()
    # 2、关闭
    def teardown_method(self):
        self.session.close()
    # 3、调用投资Api接口
    @pytest.mark.parametrize("amount,expect_text",read_json("invest.json","invest"))
    def test01_invest(self,amount,expect_text):
        try:
            resp = self.invest.api_invest(amount)
            logger.info("请求后台投资接口测试结果:{}".format(resp.json()))
            if expect_text == "OK":
                data = read_html(resp)
                resp = self.session.post(url = data[0],data=data[1])
                logger.info("三方后台投资接口测试结果:{}".format(resp.text))
            common_assert(resp,expect_text=expect_text)
        except Exception as e:
            logger.error(e)
            raise